/*
 *  JFrameEditorDeTimes.java
 *  Copyright (C) 2008  Tiago Silva Loureiro
 *  This File is part of Bier Manager.
 *  Bier Manager a is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*  Team Editor - Bier Manager
 * 
 *  With it you can create a package of teams to be used in bmanager.
 *  It has capacity to insert a limited number of teams, saving files
 *  in '.tim' extension.
 * 
 * * Created on September, 19/2008, 23:15
 */

/*  Editor de Times - Bier Manager
 * 
 *  Módulo utilizado para criação do pacote de times para utilização no
 *  bmanager. Possui capacidade para criação de um número máximo de times,
 *  salvando os arquivos na extensão '.tim' .
 * 
 * * Criado em 19 de Setembro de 2008, 23:15
 */
 
/* 
 *  (Implementado!)Adicionar inclusão de bandeira para cada time.
 *  //TODO : Adicionar propriedades de jogadores baseada em herança. Ex.:( Goleiro extends Jogador )
 */

package biermanager.editorDeTimes.interfaceGrafica;

import com.db4o.IncompatibleFileFormatException;
import com.db4o.ObjectSet;                      //Database settings - GPL Licensed !!!
import biermanager.nucleo.DadosTimes;
import biermanager.nucleo.Jogador;
import biermanager.nucleo.Plantel;
import biermanager.nucleo.Time;
import com.db4o.Db4oIOException;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import org.jvnet.substance.SubstanceLegacyDefaultLookAndFeel;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.skin.SubstanceAutumnLookAndFeel;
import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
import org.jvnet.substance.skin.SubstanceBusinessBlueSteelLookAndFeel;
import org.jvnet.substance.skin.SubstanceChallengerDeepLookAndFeel;
import org.jvnet.substance.skin.SubstanceCremeLookAndFeel;
import org.jvnet.substance.skin.SubstanceEmeraldDuskLookAndFeel;
import org.jvnet.substance.skin.SubstanceMagmaLookAndFeel;
import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;
import org.jvnet.substance.skin.SubstanceNebulaBrickWallLookAndFeel;
import org.jvnet.substance.skin.SubstanceNebulaLookAndFeel;
import org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel;
import org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel;
import org.jvnet.substance.skin.SubstanceRavenLookAndFeel;
import org.jvnet.substance.skin.SubstanceSaharaLookAndFeel;

/**
 * @author  Tiago Silva Loureiro
 */

public class JFrameEditorDeTimes extends javax.swing.JFrame {

    /** Construtor do Editor de Times
     * 
     * Inicia as variáveis da GUI, centraliza o JFrame na tela,
     * atualiza as opções de idioma do JOptionPane, e desabilita
     * aba Edição do Plantel.
     *      
     */
    public JFrameEditorDeTimes() {
            //setLookAndFeel();
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
        setLocation( (int)( ( screenSize.getWidth() - this.getWidth() ) / 2 ), (int)( (screenSize.getHeight() - this.getHeight() - 40) / 2 ) );
        UIManager.put("OptionPane.yesButtonText", "Sim");
        UIManager.put("OptionPane.cancelButtonText", "Cancelar");
        UIManager.put("OptionPane.noButtonText", "Não");  
        UIManager.put("OptionPane.okButtonText", "OK");
        UIManager.put("OptionPane.message", "Mensagem ao usuário");
        UIManager.put("ColorChooser.previewText" , " Exemplo de cor ");
        UIManager.put("ColorChooser.cancelText" , "Cancelar");
        UIManager.put("ColorChooser.resetText" , "Branco");
        UIManager.put("ColorChooser.sampleText" , " Texto de amostra  Texto de Amostra ");
        UIManager.put("ColorChooser.swatchesNameText" , " Simples ");       //Traduções para o portugues do Brasil
        
        
        //Variaveis definições da Interface Grafica
        
        tituloDaJanela = " Editor de Times - Bier Manager - ";
        nomeDoDiretorio = "";
        nomeDoArquivo = null;
        tabelaPlantel = (DefaultTableModel) jtTabelaPlantel.getModel();
        tabelaTimes = (DefaultTableModel) jtTabelaTimes.getModel();
        jtpAbas.setEnabledAt( 1, false );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jtpAbas = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtTabelaTimes = new javax.swing.JTable();
        jbEditarDadosDoTime = new javax.swing.JButton();
        jbInserirNovoTime = new javax.swing.JButton();
        jbExcluirTime = new javax.swing.JButton();
        jbEditarPlantel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jlNomeCompleto = new javax.swing.JLabel();
        jlNomeAbreviado = new javax.swing.JLabel();
        jlForca = new javax.swing.JLabel();
        jlBandeira = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtTabelaPlantel = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jbInserirJogador = new javax.swing.JButton();
        jbEditarJogador = new javax.swing.JButton();
        jbExcluirJogador = new javax.swing.JButton();
        jbSalvarPlantel = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        jButton2 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jButton4 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Editor de Times - BierManager");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFont(new java.awt.Font("Calibri", 1, 14));
        setIconImage(Toolkit.getDefaultToolkit().getImage("ico.gif"));
        setName("JFrameEditorDeTimes"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jtpAbas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jPanel2.setMaximumSize(new java.awt.Dimension(620, 480));
        jPanel2.setMinimumSize(new java.awt.Dimension(620, 480));
        jPanel2.setOpaque(false);

        jScrollPane1.setFont(new java.awt.Font("Arial", 1, 12));

        jtTabelaTimes.setFont(new java.awt.Font("Tahoma", 1, 12));
        jtTabelaTimes.setForeground(new java.awt.Color(255, 255, 255));
        jtTabelaTimes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome Completo", "Nome Abreviado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtTabelaTimes.setFillsViewportHeight(true);
        jtTabelaTimes.setGridColor(new java.awt.Color(255, 255, 255));
        jtTabelaTimes.setSelectionBackground(new java.awt.Color(0, 0, 102));
        jtTabelaTimes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jtTabelaTimes.setShowHorizontalLines(false);
        jtTabelaTimes.setShowVerticalLines(false);
        jtTabelaTimes.getTableHeader().setResizingAllowed(false);
        jtTabelaTimes.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jtTabelaTimes);
        jtTabelaTimes.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        jbEditarDadosDoTime.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbEditarDadosDoTime.setText("Editar Time");
        jbEditarDadosDoTime.setToolTipText("Clique para editar os dados do time selecionado");
        jbEditarDadosDoTime.setEnabled(false);
        jbEditarDadosDoTime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarDadosDoTimeDadosDoTimeActionPerformed(evt);
            }
        });

        jbInserirNovoTime.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbInserirNovoTime.setText("Inserir novo Time");
        jbInserirNovoTime.setToolTipText("Clique para Inserir um novo Time no pacote");
        jbInserirNovoTime.setEnabled(false);
        jbInserirNovoTime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbInserirNovoTimeNovoTimeActionPerformed(evt);
            }
        });

        jbExcluirTime.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbExcluirTime.setText("Excluir Time");
        jbExcluirTime.setToolTipText("Clique para excluir um time existente");
        jbExcluirTime.setEnabled(false);
        jbExcluirTime.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbExcluirTimeTimeActionPerformed(evt);
            }
        });

        jbEditarPlantel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbEditarPlantel.setText("Editar Plantel");
        jbEditarPlantel.setToolTipText("Clique para editar o plantel do time selecionado");
        jbEditarPlantel.setEnabled(false);
        jbEditarPlantel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarPlantelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbExcluirTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbEditarPlantel, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbEditarDadosDoTime, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbInserirNovoTime, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                .addGap(15, 15, 15))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(jbInserirNovoTime, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbEditarDadosDoTime, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbEditarPlantel, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbExcluirTime, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jtpAbas.addTab("Edição dos Times", jPanel2);

        jPanel1.setEnabled(false);
        jPanel1.setMaximumSize(new java.awt.Dimension(620, 480));
        jPanel1.setMinimumSize(new java.awt.Dimension(620, 480));
        jPanel1.setOpaque(false);

        jlNomeCompleto.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jlNomeCompleto.setText("Nome Do Time");

        jlNomeAbreviado.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlNomeAbreviado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlNomeAbreviado.setText("Abreviado");

        jlForca.setFont(new java.awt.Font("Arial Black", 0, 36));
        jlForca.setName("jlForca"); // NOI18N

        jtTabelaPlantel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jtTabelaPlantel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Craque", "Posição"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtTabelaPlantel.setFillsViewportHeight(true);
        jtTabelaPlantel.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jtTabelaPlantel.setShowHorizontalLines(false);
        jtTabelaPlantel.setShowVerticalLines(false);
        jtTabelaPlantel.getTableHeader().setResizingAllowed(false);
        jtTabelaPlantel.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(jtTabelaPlantel);
        jtTabelaPlantel.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jtTabelaPlantel.getColumnModel().getColumn(0).setResizable(false);
        jtTabelaPlantel.getColumnModel().getColumn(1).setResizable(false);
        jtTabelaPlantel.getColumnModel().getColumn(2).setResizable(false);

        jPanel3.setOpaque(false);

        jbInserirJogador.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbInserirJogador.setText("Inserir Jogador");
        jbInserirJogador.setToolTipText("Clique para inserir um jogador");
        jbInserirJogador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbInserirJogadorActionPerformed(evt);
            }
        });

        jbEditarJogador.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbEditarJogador.setText("Editar Jogador");
        jbEditarJogador.setToolTipText("Clique para editar um jogador selecionado");
        jbEditarJogador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarJogadorActionPerformed(evt);
            }
        });

        jbExcluirJogador.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbExcluirJogador.setText("Excluir Jogador");
        jbExcluirJogador.setToolTipText("Clique para excluir um jogador selecionado");
        jbExcluirJogador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbExcluirJogadorActionPerformed(evt);
            }
        });

        jbSalvarPlantel.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbSalvarPlantel.setText("Salvar Alterações");
        jbSalvarPlantel.setToolTipText("Clique para salvar o plantel atual");
        jbSalvarPlantel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalvarPlantelActionPerformed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Tahoma", 0, 12));
        jbCancelar.setText("Cancelar Alterações");
        jbCancelar.setToolTipText("Clique para sair sem salvar as alterações");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbInserirJogador, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                    .addComponent(jbEditarJogador, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                    .addComponent(jbExcluirJogador, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                    .addComponent(jbCancelar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbSalvarPlantel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jbInserirJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEditarJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbExcluirJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbSalvarPlantel, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jlForca, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlNomeCompleto, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jlNomeAbreviado, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jlBandeira, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jlNomeCompleto, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                        .addComponent(jlNomeAbreviado, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jlBandeira, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jlForca, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jlNomeCompleto.getAccessibleContext().setAccessibleName("jlNomeDoTime");
        jlNomeAbreviado.getAccessibleContext().setAccessibleName("jlNomeAbreviado");
        jlForca.getAccessibleContext().setAccessibleName("jlForca");

        jtpAbas.addTab("Edição do plantel", jPanel1);

        jToolBar1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.add(jSeparator1);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/biermanager/editorDeTimes/imagens/misc_51.png"))); // NOI18N
        jButton1.setText("Novo Pacote de Times");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);
        jToolBar1.add(jSeparator5);

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/biermanager/editorDeTimes/imagens/misc_50.png"))); // NOI18N
        jButton2.setText("Abrir Pacote de Times");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);
        jToolBar1.add(jSeparator4);

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/biermanager/editorDeTimes/imagens/help.png"))); // NOI18N
        jButton4.setText("Sobre o Bier Manager");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);
        jToolBar1.add(jSeparator2);

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/biermanager/editorDeTimes/imagens/g32.png"))); // NOI18N
        jButton3.setText("Fechar o Editor de Times");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jtpAbas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 619, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtpAbas, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jtpAbas.getAccessibleContext().setAccessibleName("Abas");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
private void jbInserirNovoTimeNovoTimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbInserirNovoTimeNovoTimeActionPerformed
    JDialogInserirTime jd = new JDialogInserirTime(this, true);
    jd.setVisible(true);
    if(jd.isActive()){
        timeTemporario = jd.getTime();
        inserirTime();
        modoEditar();
        
        
    }
}//GEN-LAST:event_jbInserirNovoTimeNovoTimeActionPerformed

private void jbEditarDadosDoTimeDadosDoTimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarDadosDoTimeDadosDoTimeActionPerformed
    if( jtTabelaTimes.getRowCount() > 0 ){
        if( jtTabelaTimes.getSelectedRow() == -1 )
            JOptionPane.showMessageDialog(null, " Selecione algum time na tabela!");
        else{
            Time timeEditado = new Time(null,null,null,0);
            int indice = jtTabelaTimes.getSelectedRow();
                try {
                    dadosTimes = new DadosTimes(nomeDoArquivo);
                } catch (Db4oIOException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IncompatibleFileFormatException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                }
            Times = dadosTimes.getAllTimes();
            timeTemporario = (Time)Times.get( indice );
            JDialogInserirTime jd = new JDialogInserirTime(this, true, timeTemporario);
            jd.setVisible(true);
            if(jd.isActive()){
                timeTemporario = jd.getTime();
                dadosTimes.saveTime( timeTemporario );
                tabelaTimes.removeRow( indice );
                tabelaTimes.insertRow(indice, new Object[]{timeTemporario.getNomeCompleto(),timeTemporario.getNomeAbreviado()} );
                dadosTimes.closeDatabase();
             }  
        else
            dadosTimes.closeDatabase();
        }
    }
}//GEN-LAST:event_jbEditarDadosDoTimeDadosDoTimeActionPerformed


private void jbExcluirTimeTimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirTimeTimeActionPerformed

    if( jtTabelaTimes.getRowCount() > 0 ){
        if( jtTabelaTimes.getSelectedRow() == -1 )
            JOptionPane.showMessageDialog(null, " Selecione algum time na tabela!");
        else{
            if (JOptionPane.showConfirmDialog(null, "Confirma exclusão do time?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
                excluirTime();
        }
    }
}//GEN-LAST:event_jbExcluirTimeTimeActionPerformed

private void jbEditarPlantelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarPlantelActionPerformed
    
    if( jtTabelaTimes.getRowCount() > 0 ){
        if( jtTabelaTimes.getSelectedRow() == -1 )
            JOptionPane.showMessageDialog(null, " Selecione algum time na tabela!");
        else{
            int indice = jtTabelaTimes.getSelectedRow();
                try {
                    dadosTimes = new DadosTimes(nomeDoArquivo);
                } catch (Db4oIOException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IncompatibleFileFormatException ex) {
                    Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
                }
            Times = dadosTimes.getAllTimes();
            timeTemporario = (Time)Times.get( indice );
            jlNomeCompleto.setText( timeTemporario.getNomeCompleto() );
            jlNomeAbreviado.setText( timeTemporario.getNomeAbreviado() );
            jlForca.setText( String.valueOf(timeTemporario.getNivelInicial() ));
            jtpAbas.setEnabledAt( 0, false );
            jtpAbas.setEnabledAt( 1, true  );
//            jPanel1.setBackground( timeTemporario.getColor()[1]);
//            for(int i = 0;  i < jPanel1.getComponentCount(); i++)
//                jPanel1.getComponent(i).setForeground(timeTemporario.getColor()[0]);
//            jtTabelaTimes.setForeground(timeTemporario.getColor()[0]);
            if( timeTemporario.getPlantel() != null )
                for( int j = 0; j < timeTemporario.getPlantel().Tamanho(); j++ )
                    tabelaPlantel.addRow(new Object[]{timeTemporario.getPlantel().getJogador(j).getNome(),timeTemporario.getPlantel().getJogador(j).getCraque(),timeTemporario.getPlantel().getJogador(j).getPosicao()});
            jtpAbas.setSelectedIndex( 1 );
        }
    }
}//GEN-LAST:event_jbEditarPlantelActionPerformed

private void jbEditarJogadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarJogadorActionPerformed
    if( tabelaPlantel.getRowCount() > 0 ){
        if( jtTabelaPlantel.getSelectedRow() == -1 )
            JOptionPane.showMessageDialog(null, " Selecione algum jogador na tabela!");
        else{
            int indice = jtTabelaPlantel.getSelectedRow();
            Jogador temporario = new Jogador();
            temporario = timeTemporario.getPlantel().getJogador( indice );
            Plantel ptemporario = new Plantel();
            JDialogInserirJogador jdit = new JDialogInserirJogador( this, true, temporario );
            jdit.setVisible(true);
            if(jdit.isActive() ){
            for( int i = 0; i < timeTemporario.getPlantel().Tamanho(); i++ )
                ptemporario.adicionaJogador( timeTemporario.getPlantel().getJogador(i));
            ptemporario.setJogador( indice, jdit.getJogador() );
            timeTemporario.setPlantel(ptemporario);
            limparTabela( tabelaPlantel);
            for( int j = 0; j < timeTemporario.getPlantel().Tamanho(); j++ )
                tabelaPlantel.addRow(new Object[]{timeTemporario.getPlantel().getJogador(j).getNome(),timeTemporario.getPlantel().getJogador(j).getCraque(),timeTemporario.getPlantel().getJogador(j).getPosicao()});
            }
        }
    }
    else
        JOptionPane.showMessageDialog(null, "Tabela vazia! Insira algum jogador para poder editar!");
}//GEN-LAST:event_jbEditarJogadorActionPerformed

private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
    
    if (JOptionPane.showConfirmDialog(null, "Deseja cancelar a edição do plantel sem salvar?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
    {
        limparTabela( tabelaPlantel );
        timeTemporario = null;
        jtpAbas.setEnabledAt( 0, true );
        jtpAbas.setEnabledAt( 1, false  );
        jtpAbas.setSelectedIndex( 0 );
        dadosTimes.closeDatabase();
    }
}//GEN-LAST:event_jbCancelarActionPerformed

private void jbInserirJogadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbInserirJogadorActionPerformed
    Plantel ptemporario = new Plantel();
    Jogador temporario = new Jogador();
    JDialogInserirJogador jdit = new JDialogInserirJogador(this, true);
    jdit.setVisible(true);
    temporario = jdit.getJogador();
    if( temporario != null ){
        if( timeTemporario.getPlantel() != null )
            for( int i = 0; i < timeTemporario.getPlantel().Tamanho(); i++ )
                ptemporario.adicionaJogador( timeTemporario.getPlantel().getJogador(i));
            ptemporario.adicionaJogador( temporario ) ;
            timeTemporario.setPlantel(ptemporario);
            limparTabela( tabelaPlantel );
            for( int indice = 0; indice < timeTemporario.getPlantel().Tamanho(); indice++ )
                tabelaPlantel.addRow(new Object[]{timeTemporario.getPlantel().getJogador(indice).getNome(),timeTemporario.getPlantel().getJogador(indice).getCraque(),timeTemporario.getPlantel().getJogador(indice).getPosicao()});
    }
}//GEN-LAST:event_jbInserirJogadorActionPerformed

private void jbSalvarPlantelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarPlantelActionPerformed
    
    if (JOptionPane.showConfirmDialog(null, "Deseja salvar as alterações no Plantel?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
    {
        dadosTimes.saveTime(timeTemporario);
        dadosTimes.closeDatabase();
        limparTabela( tabelaPlantel );
        timeTemporario = null;
        jtpAbas.setEnabledAt( 0, true );
        jtpAbas.setEnabledAt( 1, false  );
        jtpAbas.setSelectedIndex( 0 );
    }
}//GEN-LAST:event_jbSalvarPlantelActionPerformed

private void jbExcluirJogadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirJogadorActionPerformed

    if( tabelaPlantel.getRowCount() > 0 ){
        if( jtTabelaPlantel.getSelectedRow() == -1 )
            JOptionPane.showMessageDialog(null, " Selecione algum jogador na tabela!");
        else{
            Plantel ptemporario = new Plantel();
            int indice = jtTabelaPlantel.getSelectedRow();
            for( int i = 0; i < timeTemporario.getPlantel().Tamanho(); i++ )
                ptemporario.adicionaJogador( timeTemporario.getPlantel().getJogador(i));
            ptemporario.retiraJogador( indice );
            timeTemporario.setPlantel(ptemporario);
            limparTabela( tabelaPlantel);
            for( int j = 0; j < timeTemporario.getPlantel().Tamanho(); j++ )
                tabelaPlantel.addRow(new Object[]{timeTemporario.getPlantel().getJogador(j).getNome(),timeTemporario.getPlantel().getJogador(j).getCraque(),timeTemporario.getPlantel().getJogador(j).getPosicao()});
       
        }
    }
    else
        JOptionPane.showMessageDialog(null, "Tabela vazia! Insira algum jogador para poder excluir!");
}//GEN-LAST:event_jbExcluirJogadorActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (JOptionPane.showConfirmDialog(null, "Deseja finalizar o Editor de Times?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
            System.exit(0);
}//GEN-LAST:event_formWindowClosing

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JDialogNovoPacote jdnp = new JDialogNovoPacote(this, true);
    jdnp.setVisible(true);
    nomeDoArquivo = jdnp.getNomeDoArquivo();
    if( nomeDoArquivo != null ){
        nomeDoArquivo = jdnp.getNomeDoArquivo();
        nomeDoArquivo = nomeDoDiretorio.concat(nomeDoArquivo);
        modoInserir();
        jbInserirNovoTimeNovoTimeActionPerformed(evt);
    }// else
        //JOptionPane.showMessageDialog(null, "Erro na nomeação do arquivo ! ","Mensagem",JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    dialogoDeArquivos = new FileDialog( this, "Escolha o pacote de times", FileDialog.LOAD );
    dialogoDeArquivos.setVisible(true);
    limparTabela(tabelaTimes);
    nomeDoDiretorio = dialogoDeArquivos.getDirectory();
    nomeDoArquivo = dialogoDeArquivos.getFile();
    if( nomeDoArquivo != null){
                    try {
        nomeDoArquivo = nomeDoDiretorio.concat(nomeDoArquivo);
                dadosTimes = new DadosTimes(nomeDoArquivo);
                        timeTemporario = new Time(null,null,null,0);
        Times = dadosTimes.getAllTimes();
        while( Times.hasNext() ){
            timeTemporario = (Time) Times.next();
            tabelaTimes.addRow(new Object[]{timeTemporario.getNomeCompleto(),timeTemporario.getNomeAbreviado()});
        }
        dadosTimes.closeDatabase();
        modoEditar();
            } catch (com.db4o.ext.Db4oException ex) {
                JOptionPane.showMessageDialog(null, "Erro na abertura do arquivo");
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(null, "Arquivo não encontrado!");
    }
    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (JOptionPane.showConfirmDialog(null, "Deseja finalizar o Editor de Times?","Editor de Times - Bier Manager", JOptionPane.YES_NO_OPTION ) == JOptionPane.OK_OPTION )
            System.exit(0);
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    JDialogSobre jdsobre = new JDialogSobre(this, true);
    jdsobre.setVisible(true);
}//GEN-LAST:event_jButton4ActionPerformed

private void inserirTime(){
    if( nomeDoArquivo != null ){
            try {
                dadosTimes = new DadosTimes(nomeDoArquivo);
            } catch (Db4oIOException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IncompatibleFileFormatException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            }
        Times = dadosTimes.getTimeByName( timeTemporario.getNomeCompleto() );
        dadosTimes.createTime( timeTemporario );
        Times = dadosTimes.getTimeByName( timeTemporario.getNomeCompleto() );
        if( Times.size() == 1 ){
            dadosTimes.closeDatabase();
            atualizarTabelaTimes(tabelaTimes);
        }
        else
            dadosTimes.closeDatabase();
            //TODO Implementar tratamento de dados, caso haja insercao dupla no banco!!!
    }
}


private void excluirTime(){
    if( nomeDoArquivo != null ){
        int indice = jtTabelaTimes.getSelectedRow();
            try {
                dadosTimes = new DadosTimes(nomeDoArquivo);
            } catch (Db4oIOException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IncompatibleFileFormatException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            }
        Times = dadosTimes.getAllTimes();
        timeTemporario = (Time)Times.get( indice );
        Times = dadosTimes.getTimeByName( timeTemporario.getNomeCompleto() );
        if( Times.size() == 1 ){
            dadosTimes.deleteTime( timeTemporario );
            tabelaTimes.removeRow( indice );
            dadosTimes.closeDatabase();
        }
        else
            dadosTimes.closeDatabase();
            //TODO Implementar tratamento de dados, caso haja insercao dupla no banco!!!
    }
}


    /**
     *      Os métods a seguir alteram a habilitação
     *      dos botões para garantir consistência de
     *      opções aos usuários.
     **/
private void modoEditar(){
    jbInserirNovoTime.setEnabled(true);
    jbEditarDadosDoTime.setEnabled(true);
    jbExcluirTime.setEnabled(true);
    jbEditarPlantel.setEnabled(true);
    this.setTitle(tituloDaJanela.concat(nomeDoArquivo));
}
private void modoInserir(){
    jbInserirNovoTime.setEnabled(true);
    jbEditarPlantel.setEnabled(false);
    jbEditarDadosDoTime.setEnabled(false);
    jbExcluirTime.setEnabled(false);
    limparTabela(tabelaTimes);
    this.setTitle(tituloDaJanela.concat(nomeDoArquivo));
}

    /*
     *  Parametro: TableModel table
     *  Limpa a tabela que add. o componente table, excluindo seus registros.
     **/
private void limparTabela(javax.swing.table.DefaultTableModel table )
{
    while( table.getRowCount() > 0 ){
        table.removeRow(0);}
}
    /*
     *  Parametro: TableModel tabelaTimes
     *  Atualiza a tabela de times
     **/
private void atualizarTabelaTimes(javax.swing.table.DefaultTableModel table ){
     if( nomeDoArquivo != null){
        limparTabela( table );
            try {
                dadosTimes = new DadosTimes(nomeDoArquivo);
            } catch (Db4oIOException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IncompatibleFileFormatException ex) {
                Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
            }
        timeTemporario = new Time(null,null,null,0);
        Times = dadosTimes.getAllTimes();
        while( Times.hasNext() ){
            timeTemporario = (Time) Times.next();
            table.addRow(new Object[]{timeTemporario.getNomeCompleto(),timeTemporario.getNomeAbreviado()});
        }
        dadosTimes.closeDatabase();
     }
     else
         JOptionPane.showMessageDialog(null, "Erro na atualização da tabela!");
}

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
                        try {
                        UIManager.setLookAndFeel(new SubstanceChallengerDeepLookAndFeel());
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(JFrameEditorDeTimes.class.getName()).log(Level.SEVERE, null, ex);
        }
        
                new JFrameEditorDeTimes().setVisible(true);  
            }
        });
        
}
    
    /*
     *  Atualiza a aparência do programa para o LookAndFeel do Sistema.
     **/    
private void setLookAndFeel() {
    try {
        UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
        SwingUtilities.updateComponentTreeUI(this);
    }catch ( Exception e ) {
        System.err.println( "Nao é possivel usar a Aparência do Sistema:" + e );
    }
}

    private ObjectSet Times;
    private String nomeDoDiretorio;
    private String nomeDoArquivo;
    private String tituloDaJanela;
    private javax.swing.table.DefaultTableModel tabelaPlantel;
    private javax.swing.table.DefaultTableModel tabelaTimes;
    private FileDialog dialogoDeArquivos;
    private Time timeTemporario;
    private DadosTimes dadosTimes;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbEditarDadosDoTime;
    private javax.swing.JButton jbEditarJogador;
    private javax.swing.JButton jbEditarPlantel;
    private javax.swing.JButton jbExcluirJogador;
    private javax.swing.JButton jbExcluirTime;
    private javax.swing.JButton jbInserirJogador;
    private javax.swing.JButton jbInserirNovoTime;
    private javax.swing.JButton jbSalvarPlantel;
    private javax.swing.JLabel jlBandeira;
    private javax.swing.JLabel jlForca;
    private javax.swing.JLabel jlNomeAbreviado;
    private javax.swing.JLabel jlNomeCompleto;
    private javax.swing.JTable jtTabelaPlantel;
    private javax.swing.JTable jtTabelaTimes;
    private javax.swing.JTabbedPane jtpAbas;
    // End of variables declaration//GEN-END:variables

}
